#ifndef CHATCLIENT_H
#define CHATCLIENT_H

#include <QObject>
#include <qbluetoothserver.h>
#include <QBluetoothSocket>
#include <QBluetoothServiceInfo>

QT_FORWARD_DECLARE_CLASS(QBluetoothSocket)

class chatclient : public QObject
{
    Q_OBJECT
public:
    explicit chatclient(QObject *parent = nullptr);
    ~chatclient();

    /* 开启客户端 */
    void startClient(const QBluetoothServiceInfo &remoteService);

    /* 停止客户端 */
    void stopClient();

    /* 发送消息 */
    void sendMessage(const QString &message);

    /* 主动断开连接 */
    void disconnect();

signals:
    /* 接收到消息信号 */
    void sig_messageReceived(const QString &sender, const QString &message);

    /* 连接信号 */
    void sig_connected(const QString &name);

    /* 断开连接信号 */
    void sig_disconnected();

private slots:
    /* 从 socket 里读取消息 */
    void readSocket();

    /* 连接 */
    void connected();

private:
    /* socket 通信 */
    QBluetoothSocket *socket = nullptr;
};

#endif // CHATCLIENT_H
